home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / pcpilot.exe / lha / SCRPUTS.ASM < prev    next >
Assembly Source File  |  1989-01-03  |  3KB  |  101 lines

  1. ;
  2. ; SCRPUTS.ASM
  3. ;
  4. ; From the book "Systems Progamming in Turbo C", by Michael J. Young
  5. ;
  6. ; These versions of ScrPutS and ScrPutWin are written specifically
  7. ; for CGA adapters that produce 'snow' when writing directly to the screen.
  8.  
  9.         EXTRN _VideoSeg:word        ; external - see scr.h
  10.  
  11.         assume    cs:_text            ; Medium,large,huge: replace '_text'
  12.                                     ; with 'filename_text'.
  13.  
  14. _text    segment byte public 'code'    ; see above comment for other models
  15.  
  16.  
  17. ; ------------------------ ScrPutS() -------------------------------
  18.  
  19. public    _ScrPutS
  20.  
  21. _ScrPutS    proc near                ; other models, replace 'near' w/ 'far'
  22.  
  23.  
  24. h_retrace    macro                    ; Pauses until the beginning of a
  25.             local    m01, m02        ; horizontal retrace
  26. m01:        in        al, dx            ; loop to complete any retrace period
  27.             test    al, 1            ; in progress
  28.             jnz        m01
  29. m02:        in        al, dx            ; loop until start of a new horizontal
  30.             test    al, 1            ; retrace
  31.             jz        m02
  32.             endm
  33.  
  34. sframe        struc                    ; template to access stack frame
  35. BasePtr        dw        ?                ; Position of saved BP register
  36. RetAd        dw        ?                ; Other models: replace 'dw' w/ 'dd'
  37. str_ad        dw        ?                ; String adress: same comment as above
  38. att            dw        ?                ; Display attribute
  39. row            dw        ?                ; Starting row
  40. col            dw        ?                ; Starting column
  41. sframe        ends
  42.  
  43. frame        equ        [bp - BasePtr]    ; Base for accessing stack frame
  44.  
  45.                                     ; Standard initialization
  46.             push    bp                ; Set up base pointer to access frame
  47.             mov        bp, sp
  48.             sub        sp, BasePtr        ; Adjust SP for local variables
  49.             push    di                ; Save C register variables
  50.             push    si
  51.  
  52.             mov        si, frame.str_ad    ; DS:SI point to start of source
  53.                                         ; string. Compact, Large, Huge:
  54.                                         ; replace this statement with:
  55.                                         ; lds    si, frame.str_ad
  56.  
  57.             mov        ax, _VideoSeg        ; Set ES to CGA buffer
  58.             mov        es, ax
  59.                                     ; Starting offset =
  60.                                     ;   (row * 160) + (col * 2)
  61.             mov        di, frame.row    ; Place row in DI & multiply by 160
  62.             mov        ax, di
  63.             mov        cl, 7
  64.             shl        di, cl
  65.             mov        cl, 5
  66.             shl        ax, cl
  67.             add        di, ax
  68.  
  69.             mov        ax, frame.col    ; Multiply col by 2
  70.             shl        ax, 1
  71.             add        di, ax            ; Add (col * 2) to DI
  72.  
  73.                                     ; Attribute in BH
  74.             mov        bh, byte ptr frame.att
  75.             mov        dx, 03dah        ; CRT status register
  76.  
  77. a01:
  78.             cmp        byte ptr [si], 0    ; Test for null termination
  79.             je        a02
  80.             mov        bl, [si]        ; Move next character to BL
  81.             inc        si
  82.             cli                        ; Disable interrupts
  83.             h_retrace                ; Wait for horizontal retrace
  84.             mov        es:[di], bl        ; Move ASCII
  85.             inc        di
  86.             h_retrace                ; Wait again
  87.             mov        es:[di], bh        ; Move ATTRIBUTE
  88.             sti                        ; Restore interrupts
  89.             inc        di                ; Increment offset in video memory
  90.             jmp        a01                ; Go back for another character
  91. a02:
  92.             pop        si                ; restore C register variables
  93.             pop        di
  94.             mov        sp, bp
  95.             pop        bp
  96.             ret                        ; Return to C program
  97.  
  98. _ScrPutS    endp
  99.  
  100. _text        ends
  101.             end